package cn.fj.hrm.fallback;

import cn.fj.hrm.client.ElasticSearchClient;
import cn.fj.hrm.basic.util.JsonResult;
import cn.fj.hrm.document.CourseDoc;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ElasticSearchClientFallbackFactory implements FallbackFactory<ElasticSearchClient>{
    @Override
    public ElasticSearchClient create(Throwable throwable) {
        return new ElasticSearchClient() {
            @Override
            public JsonResult saveBatch(List<CourseDoc> courseDocList) {
                throwable.printStackTrace();
                return JsonResult.me().setSuccess(false).setMsg("全文检索服务saveBatch调用失败：" + throwable.getMessage());
            }


            @Override
            public JsonResult deleteByIds(List<Long> ids) {
                throwable.printStackTrace();
                return JsonResult.me().setSuccess(false).setMsg("全文检索服务deleteByIds调用失败：" + throwable.getMessage());
            }
        };
    }
}
